package com.bt.mes.common.util;

import java.io.FileInputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.bt.mes.common.bean.entity.LoadHistoryConfig;

/**
 * 功能有两个 1.读取配置档. 2.更新表时: 确定是否需要发送Queue.
 *
 */
@Component("tableConfigUtil")
public class TableConfigUtil {
	@Resource
	private LoadHistoryConfig loadHistoryConfig;

	private Map<String, Boolean> tableConfigMap;

	@PostConstruct
	public void getConfigFile() {
		String hisTblFile = loadHistoryConfig.getHistoryIniFile();

		Properties hisProperties = new Properties();
		String opeTableName = null;
		try {

			hisProperties.load(new FileInputStream(hisTblFile));
			Set<Object> keySet = hisProperties.keySet();

			tableConfigMap = new HashMap<String, Boolean>();

			for (Object object : keySet) {
				opeTableName = object.toString();
				opeTableName = opeTableName.substring(0, opeTableName.indexOf("."));// 字符串截取
																					// ....
				tableConfigMap.put(opeTableName, true);
			}

		} catch (Exception e) {
			tableConfigMap = null;
			e.printStackTrace();
		}
	}

	public boolean checkSendHis(String _opeTableName) {
		if (tableConfigMap != null) {
			if (tableConfigMap.get(_opeTableName) != null && tableConfigMap.get(_opeTableName) == true) {
				return true;
			}
		}

		return false;
	}

	public LoadHistoryConfig getLoadHistoryConfig() {
		return loadHistoryConfig;
	}

}
